<?php
session_start();
	require 'include/configDB.php';
	if (! isset($_SESSION['role']) || ($_SESSION['role'] != "Admin") && ($_SESSION['role'] != "Staff Tata Usaha")) {
  		header('Location: login.php');
	}
	$id = $_GET['id'];
	$query = mysql_query("SELECT * FROM jadwal_pelajaran WHERE id=$id");
	$data = mysql_fetch_assoc($query);
	$id_kelas = $data['id_kelas'];
	$query_kelas = mysql_query("SELECT * FROM kelas WHERE id=$id_kelas");
	$kelas_data = mysql_fetch_assoc($query_kelas);
	$tingkat = $kelas_data['tingkat'];
	$id_jurusan = $kelas_data['id_jurusan'];
	$query_jurusan = mysql_query("SELECT * FROM jurusan WHERE id=$id_jurusan");
	$jurusan_data = mysql_fetch_assoc($query_jurusan);
	$nama_jurusan = $jurusan_data['nama'];
	$no_kelas = $kelas_data['nomor'];



?>
<!DOCTYPE html
 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Jadwal Pelajaran</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="clockp.js"></script>
<script type="text/javascript" src="clockh.js"></script> 
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
	
	function validasi(){

		if (document.edit_jadwal.hari.value == "NULL") {
			alert("Hari harus diisi!");
			return false;
		}

		if (document.edit_jadwal.id_matpel.value == "NULL") {
			alert("Mata Pelajaran harus diisi!");
			return false;
		}

		if (document.edit_jadwal.id_guru.value == "NULL") {
			alert("Guru harus diisi!");
			return false;
		}

		if (document.edit_jadwal.waktu_mulai.value == "NULL") {
			alert("Waktu mulai harus diisi");
			return false;
		}

		if (document.edit_jadwal.waktu_selesai.value == "NULL") {
			alert("Waktu akhir harus diisi");
			return false;
		}
	}
	
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
		
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>
    </div>  
    
    <div class="right_content">
	<h2>Edit Jadwal Pelajaran</h2>
		<div id="stylized" class="myform">
			<form id="edit_jadwal" name="edit_jadwal" method="post" action="include/edit_jadwal_pelajaran.php" onsubmit='return validasi();'>
				<input type="hidden" name="id" value="<?=$id?>" />
			<h1>Jadwal Pelajaran</h1>
			<table>
				<tr>
					<td>
						<label>Tahun Ajaran
							 <span class="small">Tahun Ajaran</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<?php
							$id_tahun_ajaran = $data['id_tahun_ajaran'];
							$tahun_ajaran_data = mysql_fetch_assoc(mysql_query("SELECT * FROM tahun_ajaran WHERE id='$id_tahun_ajaran'"));
						?>
						<input type="text" name="tahun_ajaran" id="tahun_ajaran" value="<?php echo $tahun_ajaran_data['tahun_ajaran'] ;?>"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Hari
							 <span class="small">isi hari</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<select name="hari" id="hari">
							<option value="NULL">Pilih</option>
							<option value="senin" <?php echo ($data['hari'] == "senin") ? "selected" : ""; ?>>Senin</option>
							<option value="selasa" <?php echo ($data['hari'] == "selasa") ? "selected" : ""; ?>>Selasa</option>
							<option value="rabu" <?php echo ($data['hari'] == "rabu") ? "selected" : ""; ?>>Rabu</option>
							<option value="kamis" <?php echo ($data['hari'] == "kamis") ? "selected" : ""; ?>>Kamis</option>
							<option value="jumat" <?php echo ($data['hari'] == "jumat") ? "selected" : ""; ?>>Jumat</option>
							<option value="sabtu" <?php echo ($data['hari'] == "sabtu") ? "selected" : ""; ?>>Sabtu</option>

						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>kelas
							<span class="small">isi kelas</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						 <input readonly type="text" name="tingkat" id="tingkat" value="<?php echo $tingkat; ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Jurusan
							 <span class="small">isi nama jurusan</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						 <input readonly type="text" name="nama_jurusan" id="nama_jurusan" value="<?php echo $nama_jurusan; ?>"  />
						 <input type="hidden" name="id_jurusan" id="id_jurusan" value="<?php echo $jurusan_data['id']; ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>No Kelas
							 <span class="small">isi nomor kelas</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						 <input readonly type="text" name="no_kelas" id="no_kelas" value="<?php echo $no_kelas; ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Mata Pelajaran
							 <span class="small">isi mata pelajaran</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<select name= "id_matpel" id="id_matpel">
							<?php 
								$id_penugasan = $data['id_penugasan'];
								$matpel = mysql_fetch_assoc(mysql_query("SELECT * FROM penugasan_guru WHERE id='$id_penugasan'"));
								$id = $matpel['id_matpel'];
						        $nama_matpel = mysql_query("SELECT * FROM mata_pelajaran WHERE id='$id'");  
								// $result = mysql_fetch_array($nama_jurusan);
						        while($matpel_data = mysql_fetch_assoc($nama_matpel))
						        {
						   		?>  
        							<option value="<?= $matpel_data['id']; ?>" <?php echo ($matpel['id_matpel'] == $matpel_data['id']) ? "selected" : "";?>><?= $matpel_data['nama']?></option>  
								<?php  
								}  
							?>  	
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>ID Guru
							 <span class="small">isi ID guru</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						 <select name="id_guru" id="id_guru">
							<?php 
								$id_penugasan = $data['id_penugasan'];
								$penugasan_data = mysql_fetch_assoc(mysql_query("SELECT * FROM penugasan_guru WHERE id='$id_penugasan'"));
								$id_guru = $penugasan_data['NIK'];
						        $nama_guru = mysql_query("SELECT * FROM guru WHERE NIK='$id_guru'");  
								// $result = mysql_fetch_array($nama_jurusan);
								
						        
						        while($guru_data = mysql_fetch_assoc($nama_guru))
						        {
						   		?>  
        							<option value="<?= $guru_data['NIK']; ?>" <?php echo ($penugasan_data['NIK'] == $guru_data['NIK']) ? "selected" : "";?>><?= $guru_data['nama']?></option>-->  
								<?php  
								}  
							?>  	
						</select>
					</td>
				</tr>    

				
				<tr>
					<td>
						<label>Waktu Mulai
							 <span class="small">isi ID waktu mulai</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<select name="waktu_mulai" id="waktu_mulai">
							<option value="NULL">Pilih</option>
							<option value="7.00" <?php echo ($data['waktu_mulai'] == "7.00") ? "selected" : ""; ?>>Jam ke - 1</option>
							<option value="7.40" <?php echo ($data['waktu_mulai'] == "7.40") ? "selected" : ""; ?>>Jam ke - 2</option>
							<option value="8.20" <?php echo ($data['waktu_mulai'] == "8.20") ? "selected" : ""; ?>>Jam ke - 3</option>
							<option value="9.00" <?php echo ($data['waktu_mulai'] == "9.00") ? "selected" : ""; ?>>Jam ke - 4</option>
							<option value="9.40" <?php echo ($data['waktu_mulai'] == "9.40") ? "selected" : ""; ?>>Jam ke - 5</option>
							<option value="10.00" <?php echo ($data['waktu_mulai'] == "10.00") ? "selected" : ""; ?>>Jam ke - 6</option>
							<option value="10.40" <?php echo ($data['waktu_mulai'] == "10.40") ? "selected" : ""; ?>>Jam ke - 7</option>
							<option value="11.20" <?php echo ($data['waktu_mulai'] == "11.20") ? "selected" : ""; ?>>Jam ke - 8</option>
							<option value="12.00" <?php echo ($data['waktu_mulai'] == "12.00") ? "selected" : ""; ?>>Jam ke - 9</option>
							<option value="12.40" <?php echo ($data['waktu_mulai'] == "12.40") ? "selected" : ""; ?>>Jam ke - 10</option>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>
						<label>Waktu Selesai
							 <span class="small">isi waktu akhir</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<select name="waktu_selesai" id="waktu_selesai">
							<option value="NULL">Pilih</option>
							<option value="7.00" <?php echo ($data['waktu_selesai'] == "7.00") ? "selected" : ""; ?>>Jam ke - 1</option>
							<option value="7.40" <?php echo ($data['waktu_selesai'] == "7.40") ? "selected" : ""; ?>>Jam ke - 2</option>
							<option value="8.20" <?php echo ($data['waktu_selesai'] == "8.20") ? "selected" : ""; ?>>Jam ke - 3</option>
							<option value="9.00" <?php echo ($data['waktu_selesai'] == "9.00") ? "selected" : ""; ?>>Jam ke - 4</option>
							<option value="9.40" <?php echo ($data['waktu_selesai'] == "9.40") ? "selected" : ""; ?>>Jam ke - 5</option>
							<option value="10.00" <?php echo ($data['waktu_selesai'] == "10.00") ? "selected" : ""; ?>>Jam ke - 6</option>
							<option value="10.40" <?php echo ($data['waktu_selesai'] == "10.40") ? "selected" : ""; ?>>Jam ke - 7</option>
							<option value="11.20" <?php echo ($data['waktu_selesai'] == "11.20") ? "selected" : ""; ?>>Jam ke - 8</option>
							<option value="12.00" <?php echo ($data['waktu_selesai'] == "12.00") ? "selected" : ""; ?>>Jam ke - 9</option>
							<option value="12.40" <?php echo ($data['waktu_selesai'] == "12.40") ? "selected" : ""; ?>>Jam ke - 10</option>
						</select>
					</td>
				</tr>
				<tr>
					<td><input type="submit" class="menuitem_red" name="submit" value="Simpan"/></td>
				</tr>
			</table>
			</form>
		</div>
	</div><!-- end of right content-->
	
            
                    
	</div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
        	<?php include 'footer.php'; ?>

    	
    </div>

</div>		
</body>
</html>